<template>
	<view class="user-container">
		<view class="cu-list menu" v-if="notices.length > 0" v-for="(notice, idx) in notices" :key="idx" :data-item="notice"
		 @click="gotoDetail(notice)">
			<view class="cu-item arrow">
				<view class="content padding-tb-sm">
					<view>
						<text class="cuIcon-notification text-cut text-green margin-right-xs"></text>
						<view class="text-cut" style="width:220px">{{notice.title}}</view>
					</view>
					<view class="text-gray text-sm">
						<text class="margin-right-xs">发布时间：</text> {{notice.timeStr}}</view>
				</view>
			</view>
		</view>
		<view class="cu-list menu" v-if="notices.length === 0">
			<view class="cu-item">
				<view class="content">
					<text class="cuIcon-notification text-grey"></text>
					<text class="text-grey">暂无公告信息</text>
				</view>
				<view class="action">
				</view>
			</view>
		</view>
		<!--加载loadding-->
		<tui-loadmore :visible="loadding" :index="3" type="primary"></tui-loadmore>
		<tui-nomore :visible="!pullUpOn" bgcolor="#fff" text="没有更多评论"></tui-nomore>
		<!--加载loadding-->
		<view class="tui-safearea-bottom"></view>
	</view>
</template>

<script>
	/** index.js **/
	import tuiLoadmore from "@/components/loadmore/loadmore"
	import tuiNomore from "@/components/nomore/nomore"
	const context = require("../../context/Java110Context.js");
	const constant = context.constant; //获取app实例
	//获取app实例
	const app = getApp().globalData;

	export default {
		components: {
			tuiLoadmore,
			tuiNomore
		},
		data() {
			return {
				communityId: "",
				notices: [],
				loadding: false,
				pullUpOn: true,
				currPageIndex: 0,
				page:1,
				pageSize: 10
			};
		},
		onLoad: function() {
			let that = this;
			that.communityId = context.getUserInfo().communityId;
			this.page = 1;
			that.getList();
		},
		onShow: function() {
			let that = this;
		},
		// 页面上拉触底事件的处理函数
		onReachBottom: function() {
			if (!this.pullUpOn) return;
			this.loadding = true
			if (this.page*10 > this.notices.length) {
				this.loadding = false;
				this.pullUpOn = false
			} else {
				this.page = this.page + 1;
				this.getList();
			}
		},
		methods: {
			getList(){
				let that = this;
				context.request({
					header: context.getHeaders(),
					url: constant.url.GetNoticeListUrl,
					method: "GET",
					data: {
						communityId: that.communityId,
						page: this.page,
						row: 10,
						noticeTypeCd:1000
					},
					success: function(res) {
						// TODO 判断
						console.log(res);
						res.data.notices.forEach(function(item, index) {
							item.timeStr = item.startTime.replace(/:\d{1,2}$/, ' ');
						});
						that.loadding = false
						that.notices = res.data.notices;
					}
				});
			},
			gotoDetail: function(_notice) {
				console.log('看看',_notice);
				let that = this;
				
				//wx.setStorageSync('notice-' + index, JSON.stringify(that.notices[index]));
				uni.navigateTo({
					url: "/pages/index/noticeDetail?noticeId=" + _notice.noticeId
				});
			},
		}
	};
</script>
<style>
	@import "../../style/main.css";
	.user-container {
	    padding: 25upx 0upx;
	    /* background-color: #F0F0F0; */
		/*border: 1px solid black;*/
	}
	
	.notice {
	    margin: 10upx 7upx;
	    padding: 25upx;
	    background-color: #ffffff;
	    border-radius: 7upx;
	}
	.title {
	    border-bottom: 1upx solid #dedede;
	    font-weight: 700;
	    font-size: 34upx;
	    color: #00AA00;
	}
	.content{
	    padding: 15upx 0;
	    font-size: 25upx;
	    color: #7B7B7B;
	    /* overflow : hidden;
	    text-overflow: ellipsis;
	    display: -webkit-box;
	    -webkit-line-clamp: 2; 
	    -webkit-box-orient: vertical; */
	}
	.txt {
	    overflow : hidden;
	    text-overflow: ellipsis;
	    display: -webkit-box;
	    -webkit-line-clamp: 2; 
	    -webkit-box-orient: vertical;
	}
	.footer {
	    padding: 15upx 0;
	    font-size: 22upx;
	    color: #ADADAD;
	}
	.cu-list+.cu-list {
	    margin-top: 10px;
	}
</style>
